package middleware

import (
	"context"
	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/common/hlog"
)

func RequestLog() app.HandlerFunc {
	return func(ctx context.Context, c *app.RequestContext) {
		hlog.CtxInfof(ctx, "【request】 URL: %s", c.Request.URI().String())
		hlog.CtxInfof(ctx, "【request】 Params: %s", string(c.Request.QueryString()))
		hlog.CtxInfof(ctx, "【request】 Header: %s", c.Request.Header.String())
		if len(c.Request.Body()) > 0 {
			hlog.CtxInfof(ctx, "【request】 Body: %s", string(c.Request.Body()))
		}
		c.Next(ctx)
		hlog.CtxInfof(ctx, "【response】body: %s", string(c.Response.Body()))
	}
}
